<template>
<div>
  <div class="loader-base" v-if="showLoad"><div class="loader-wrap"></div></div>
  <div class="feedback-textarea">
    <textarea placeholder="字数200字以内" maxlength="200" v-model="Memo"></textarea>
  </div>
  <div class="feedback-footer">
    <label>
      <input type="checkbox" class="list-radio-check" v-model="checkBtn">
      <span class="list-radio-circle"></span>
      <em class="txt">匿名</em>
    </label>
  </div>
  <div class="feedback-btn"><div class="fb-btn" @click="submit">提交</div></div>
</div>
</template>

<script>
export default {
  data() {
    return {
      showLoad:false,
      checkBtn:false,
      Memo:''
    }
  },
  computed:{
    userinfo(){
      if(localStorage.UserInfo){
        return JSON.parse(localStorage.UserInfo)
      };
    },
  },
  methods:{
    submit(){
      var self = this;
      var IsAnonymous = '';
      this.checkBtn ? IsAnonymous = 'Y': IsAnonymous = 'N';
      if(this.Memo == ''){
        this.$vux.toast.show({
          type: "warn", //success, warn, cancel, text
          text: '反馈内容不能为空'
        });
        return false;
      }
      var usertype ='1';
      if (this.userinfo.UserBizType=='Driver') {
        usertype='2';
      }
      var query = {
        TenantGuid: this.userinfo.TenantGuid,
        CorpGuid: this.userinfo.CorpGuid,
        Memo: this.Memo,
        LoginedStaffID: this.userinfo.StaffID,
        LoginedName: this.userinfo.Name || this.userinfo.LogonUser,
        IsAnonymous: IsAnonymous,
        FeedbackPicture:usertype
      }

      this.showLoad = true;
      
      this.Ajax.post("AddFeedback", query).then(function(resp) {
        self.showLoad = false;
        if(resp.IsSuccess) {
          self.$vux.toast.show({
            type: "warn", //success, warn, cancel, text
            text: "反馈完成，谢谢您的支持",
            onHide(){
              self.$router.push({
                path:'/user',
                query:{type: self.userinfo.UserBizType.toLowerCase()}
              });
            }
          });
        } 
        else
        {
          self.$vux.toast.show({
            type: "warn", //success, warn, cancel, text
            text: resp.ErrorMessage
          });
        }
      });
    }
  }
}
</script>